package pixeleditor.gui;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.MouseListener;
import java.util.ResourceBundle;

import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.border.TitledBorder;

import common.gui.IViewable;
import common.i18n.ChangeLanguage;
import common.i18n.IChangeLanguage;

import pixeleditor.core.Board;
import pixeleditor.ctrl.ControlFactory;

@SuppressWarnings("serial")
public class ChooseColorPanel extends JPanel implements IChangeLanguage, IViewable {

	private JLabel color = new JLabel();
	
	public ChooseColorPanel() {
		ChangeLanguage.addObserver(this);
		initComponents();
		initControls();
	}
	
	private void initComponents() {
		
		setPreferredSize(new Dimension(70,70));
		setLanguage(ChangeLanguage.currentLanguage);
		color.setBackground(Board.getInstance().getPaintSetup().getCurrentColor());
		color.setOpaque(true);
		color.setPreferredSize(new Dimension(30,30));
		add(color);
	}
	
	private void initControls() {
		ControlFactory.getControl(ControlFactory.CHOOSE_COLOR_CTRL).addView(this);
		MouseListener ml = (MouseListener) ControlFactory.getControl(ControlFactory.CHOOSE_COLOR_CTRL);
		color.addMouseListener(ml);
	}

	@Override
	public void setLanguage(ResourceBundle rb) {
		setBorder(new TitledBorder(rb.getString("editorColor")));	
	}

	@Override
	public void updateView(Object o) {
		color.setBackground((Color)o);
	}
}
